import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 跳转相同路径时不报错
// const originalPush = VueRouter.prototype.push
// VueRouter.prototype.push = function push(location) {
//   return originalPush.call(this, location).catch(err => err)
// }

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../views/home/index.vue')
  },
  {
    path: '/home/city',
    name: 'city',
    meta: {
      title: "不凡"
    },
    component: () => import('../views/home/city/index.vue')
  },
  {
    path: '/home/search',
    name: 'search',
    meta: {
      title: "不凡"
    },
    component: () => import('../views/home/search/index.vue')
  },
  {
    path: '/home/brand',
    name: 'brand',
    meta: {
      title: "不凡"
    },
    component: () => import('../views/home/brand/index.vue')
  },
  {
    path: '/home/brand/brandInfo',
    name: 'brandInfo',
    meta: {
      title: "不凡"
    },
    component: () => import('../views/home/brand/brandInfo/index.vue')
  },
  {
    path: '/home/goods',
    name: 'goods',
    meta: {
      title: "不凡"
    },
    component: () => import('../views/home/goods/index.vue')
  },
  {
    path: '/home/goods/detail',
    name: 'detail',
    meta: {
      title: "不凡",
    },
    component: () => import('../views/home/goods/detail/index.vue')
  },
  {
    path: '/topic',
    name: 'topic',
    component: () => import('../views/topic/index.vue')
  },
  {
    path: '/topic/topicDetail',
    name: 'topicDetail',
    meta: {
      title: "分类详情"
    },
    component: () => import('../views/topic/topicDetail/index.vue')
  },
  {
    path: '/category',
    name: 'category',
    component: () => import('../views/category/index.vue')
  },
  {
    path: '/category/categoryList',
    name: 'categoryList',
    meta: {
      title: "不凡",
    },
    component: () => import('../views/category/categoryList/index.vue')
  },
  {
    path: '/cart',
    name: 'cart',
    component: () => import('../views/cart/index.vue')
  },
  {
    path: '/cart/order',
    name: 'order',
    meta: {
      title: "不凡"
    },
    component: () => import('../views/cart/order/index.vue')
  },
  {
    path: '/my',
    name: 'my',
    component: () => import('../views/my/index.vue')
  },
  {
    path: '/my/address',
    name: 'address',
    meta: {
      title: "不凡"
    },
    component: () => import('../views/my/address/index.vue')
  },
  {
    path: '/my/address/addressDetail',
    name: 'addressDetail',
    meta: {
      title: "不凡"
    },
    component: () => import('../views/my/address/addressDetail/index.vue')
  },
  {
    path: '/my/collect',
    name: 'collect',
    meta: {
      title: "不凡"
    },
    component: () => import('../views/my/collect/index.vue')
  },
  {
    path: '/my/feedback',
    name: 'feedback',
    meta: {
      title: "不凡"
    },
    component: () => import('../views/my/feedback/index.vue')
  }
]

const router = new VueRouter({
  routes
})

// 跳转新页面后回到顶部
router.afterEach((to, from, next) => {
  window, scrollTo(0, 0);
})

export default router
